// 引入封装好的 post 请求
import post from '../config/post';
import get from '../config/get';


const ADMIN_BASE_URL = "api/admin";

// 缓存管理
const REDIS_URL = "/redisAdmin";
//字典管理
const DICT_URL = "/dictAdmin";

// 缓存管理
const GET_CACHE_VALUES_BY_TYPE_URL = ADMIN_BASE_URL + REDIS_URL+ '/getCacheValuesByType';
//字典管理
const CREATE_DICT_URL = ADMIN_BASE_URL + DICT_URL + '/dict/create';
const QUERY_PAGE_DICT_URL = ADMIN_BASE_URL + DICT_URL + '/dict/page';
const DELETE_DICT_URL = ADMIN_BASE_URL + DICT_URL + '/dict/delete';
const UPDATE_DICT_URL = ADMIN_BASE_URL + DICT_URL + '/dict/update';
const GET_DICT_DETAILS_URL = ADMIN_BASE_URL + DICT_URL + '/details'; // 字典详细信息 URL
const GET_DICT_VALUES_URL = ADMIN_BASE_URL + DICT_URL + '/values';   // 字典值信息 URL
const BATCH_DICT_VALUES_SAVE_URL = ADMIN_BASE_URL + DICT_URL + '/dictValue/BatchSave';
const GET_DROPDOWN_INFO_URL = ADMIN_BASE_URL + DICT_URL + '/dropdown';
// 获取指定数据库中某种类型的缓存值
const getCacheValuesByType = (params, successCallback, failCallback) =>
    post(GET_CACHE_VALUES_BY_TYPE_URL, params, successCallback, failCallback);

//字典管理
const createDict = (params, successCallback, failCallback) =>
    post(CREATE_DICT_URL, params, successCallback, failCallback);
const queryPageDicts = (params, successCallback, failCallback) =>
    post(QUERY_PAGE_DICT_URL, params, successCallback, failCallback);
const deleteDict = (params, successCallback, failCallback) => {
    post( `${DELETE_DICT_URL}?dictId=${params}`,null , successCallback, failCallback)};
const updateDict = (params, successCallback, failCallback) =>
    post(UPDATE_DICT_URL, params, successCallback, failCallback);
const batchDictValuesSave = (params, successCallback, failCallback) =>
    post(BATCH_DICT_VALUES_SAVE_URL, params, successCallback, failCallback);
const getDictDetails = (dictId, successCallback, failCallback) =>
    get(`${GET_DICT_DETAILS_URL}/${dictId}`, {}, successCallback, failCallback);
const getDictValues = (dictId, successCallback, failCallback) =>
    get(`${GET_DICT_VALUES_URL}/${dictId}`, {}, successCallback, failCallback);
const getDropdownInfo = (dictName, spaceId, successCallback, failCallback) => {
    // 构建请求 URL，包含可选的 spaceId 参数
    const url = `${GET_DROPDOWN_INFO_URL}?dictName=${dictName}${spaceId ? `?spaceId=${spaceId}` : ''}`;
    get(url, {}, successCallback, failCallback);
};


// 导出缓存管理请求函数，便于其他模块使用
export { getCacheValuesByType,createDict,queryPageDicts,getDictDetails,
    getDictValues,batchDictValuesSave,deleteDict,updateDict,getDropdownInfo };
